package com.mg.operating.controller;

import com.mg.common.vo.ResponseResult;
import com.mg.operating.entity.ConfirmVo;
import com.mg.operating.entity.VideoComments;
import com.mg.operating.service.ViCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/comment")
public class CommentController {


    @Resource
    ViCommentService viCommentService;

    /**
     * 添加评论
     * @param videoComments 操作评论的对象
     * @return
     */
    @PostMapping("/complus")
    public ResponseResult commentPlus(@RequestBody VideoComments videoComments){
        int i = viCommentService.commentPlus(videoComments);
        if (i==0){
            return ResponseResult.error();
        }
        return ResponseResult.ok();
    }

    /**
     * 删除评论
     * @param id 操作评论的对象id
     * @return
     */
    @DeleteMapping("/comless")
    public ResponseResult commentLess(@RequestParam int id){
        int i = viCommentService.commentLess(id);
        if (i==0){
            return ResponseResult.error();
        }
        return ResponseResult.ok();
    }

    /**
     * 评论转发数
     * @param id 操作对象id
     * @param confirm 判断是否确认转发值1为确认
     * @return
     */
    @GetMapping("/forWardplus")
    public ResponseResult forWardPlus(@RequestParam int id, @RequestParam int confirm){
        ConfirmVo confirmVo = viCommentService.forWardPlus(id, confirm);
        if (confirmVo==null){
            return ResponseResult.error();
        }
        return ResponseResult.ok(confirmVo);
    }

    /**
     * 添加评论点赞数
     * @param id 操作对象的id
     * @return
     */
    @GetMapping("/like")
    public ResponseResult like(int id){
        int like = viCommentService.like(id);
        if (like==0){
            return ResponseResult.error();
        }
        return ResponseResult.ok();
    }
}
